package com.senven.address.controller;


import com.senven.address.service.AddressService;
import com.senven.common.entity.Address;
import com.senven.common.pojo.vo.CommonResult;
import io.swagger.models.auth.In;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author YSH
 * @since 2022-09-05
 */
@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private AddressService addressService;



    @PostMapping("/insertAddress")
    public CommonResult insertAddress (@RequestBody Address address,HttpServletRequest request){
        String token = request.getHeader("token");
        return addressService.insertAddress(token,address);
    }


    @PostMapping("/findAllAddress")
    public CommonResult findAllAddress(HttpServletRequest request){
        String token = request.getHeader("token");
        return addressService.findAllAddress(token);
    }

    @PostMapping("/delAddress")
    public CommonResult delAddress(Integer id){
        return addressService.delAddress(id);
    }

    @PostMapping("/findAddressByid")
    public CommonResult findAddressByid(Integer id){
        return addressService.findAddressByid(id);
    }

    @PostMapping("/updateAddressByid")
    public CommonResult updateAddressByid(Integer id,@RequestBody Address address){
        System.out.println(id);
        System.out.println(id);
        address.setId(id);
        CommonResult commonResult = addressService.updateAddressByid(address);
        System.out.println(commonResult);
        return commonResult;
    }

    /*@PostMapping("/updateAddress")
    public CommonResult updateAddress(Integer id){
        return addressService.updateAddress(id);
    }*/

}
